define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'finance/index',
                    adds_url: 'financev/index',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    aa_url: '',
                    table: 'task',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'title', title:'任务名称'},
                        {field: 'price', title: '任务单价',operate: false},
                        {field: 'commission', title:'佣金',operate: false},
                        {field: 'endtime', title:'截止时间', formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'places', title:'名额',operate: false},
                        {field: 'number', title:'完成人数',operate: false},
                        {field: 'expenditure', title: '任务支出',operate: false},
                        {field: 'income', title:'任务收入',operate: false},
                        {field: 'onefee', title: '一级支出',operate: false},
                        {field: 'twofee', title: '二级支出',operate: false},
                        {field: 'zincome', title: '总收入',operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                              buttons: [{
                                    name: 'adds',
                                    text:'查看详情',
                                    icon: 'fa fa-plus',
                                    classname: 'btn btn-info ',
                                    url: 'financev/index'
                                }],
                            formatter: Table.api.formatter.operate}
              
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
              formatter: {
                sex: function (value) {
                     if(value==1)
                    {
                        return '男';
                    }
                    else if(value==2)
                    {
                        return '女';
                    }
                    else
                    {
                        return '不限制';
                    }
                }
       
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});

